'use strict';

const Controller = require('egg').Controller;
const Redis = require('ioredis');

class DefaultController extends Controller {
  async ping() {
    const ctx = this.ctx;
    const redis = new Redis(this.config.redis.client);
    redis.subscribe('ManageNotice', function(err, count) {
      console.log('subscribe:', err, count);
    });
    redis.on('message', function(channel, message) {
      if (message) {
        console.log('message:', channel,message);
        const data = JSON.parse(message);
        switch (parseInt(data.event)) {
          case 1:
            ctx.socket.emit('play', message);
            break;
          default:
            ctx.socket.emit('res', 'message error');
            break;
        }
      }
    });
    await ctx.socket.emit('res', 'test');
  }
}

module.exports = DefaultController;

